package com.glorysoft.tonglingxjpda.model

import com.glorysoft.tonglingxjpda.base.BaseRepository
import com.glorysoft.tonglingxjpda.base.Constant
import com.glorysoft.tonglingxjpda.entity.*
import com.google.gson.JsonObject
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * FileName: TrackInRepository
 * Author: XJH
 * Date: 2021/5/25 15:06
 * Description:
 * History:
 */
class TaskRepository : BaseRepository() {
    private val MES_URL = "/esbrest/RestService/postrequest"


    suspend fun getOrderInfo(map: JsonObject): OrderListEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLPOS"))
            .toResponse<OrderListEntity>()
            .await()
    }

    suspend fun getOrderInfoByDocID(map: JsonObject): OrderListEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLPOS"))
            .toResponse<OrderListEntity>()
            .await()
    }

    /**
     * 获取客户信息
     */
    suspend fun getCustom(map: JsonObject): CustomEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLCUSTOMER"))
            .toResponse<CustomEntity>()
            .await()
    }

    /**
     * 获取BOM信息
     */
    suspend fun getBom(map: JsonObject): CustomEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLBOM"))
            .toResponse<CustomEntity>()
            .await()
    }

    /**
     * 保存PO信息
     */
    suspend fun savePo(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLPOS"))
            .toResponse<Any>()
            .await()
    }

    /**
     * 获取刻印号信息
     */
    suspend fun getKyh(map: JsonObject): KyhEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLCOMPONENTUMIT"))
            .toResponse<KyhEntity>()
            .await()
    }

    /**
     * 获取刻印号信息
     */
    suspend fun getHint(map: JsonObject): KyhEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLCOMPONENTUMIT"))
            .toResponse<KyhEntity>()
            .await()
    }

    /**
     * 保存刻印号信息
     */
    suspend fun saveKyh(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLCOMPONENTUMIT"))
            .toResponse<Any>()
            .await()
    }

    /**
     * 保存刻印号信息
     */
    suspend fun getDefectCode(map: JsonObject): DefectCodeEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLBAD"))
            .toResponse<DefectCodeEntity>()
            .await()
    }

    /**
     * 保存刻印号信息
     */
    suspend fun getDefectInfo(map: JsonObject): DefectEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLBAD"))
            .toResponse<DefectEntity>()
            .await()
    }

    /**
     * 保存刻印号信息
     */
    suspend fun saveDefect(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLBAD"))
            .toResponse<Any>()
            .await()
    }

    /**
     * 删除不良信息
     */
    suspend fun deleteDefect(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLBAD"))
            .toResponse<Any>()
            .await()
    }

    suspend fun track(map: JsonObject,messageName : String): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,messageName))
            .toResponse<Any>()
            .await()
    }

    suspend fun getBatchInfo(map: JsonObject): BatchListEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.QUNXINLOTQUERY"))
            .toResponse<BatchListEntity>()
            .await()
    }

    suspend fun getEdcInfo(map: JsonObject): EdcEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.QUNXINLOTEDC"))
            .toResponse<EdcEntity>()
            .await()
    }

    suspend fun getPackageInfo(map: JsonObject): BoxEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.QUNXINBOX"))
            .toResponse<BoxEntity>()
            .await()
    }


    suspend fun saveFinCheck(map: JsonObject): DefectEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"TL.TLTRACKPIC"))
            .toResponse<DefectEntity>()
            .await()
    }
}